package com.xyht.sca_s.student_manage_system.modules.assetFixedInventory.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.assetFixedInventory.entity.req.SmsAssetInventoryDetailReq;
import com.xyht.sca_s.student_manage_system.modules.assetFixedInventory.entity.req.SmsAssetInventoryPlanFinishReq;
import com.xyht.sca_s.student_manage_system.modules.assetFixedInventory.service.SmsAssetInventoryService;
import com.xyht.sca_s.student_manage_system.modules.assetFixedSelfInspection.entity.req.SmsAssetSelfInspectionDetailReq;
import com.xyht.sca_s.student_manage_system.modules.assetFixedSelfInspection.entity.req.SmsAssetSelfInspectionPlanFinishReq;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 我的资产 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-09-29
 */
@RestController
@RequestMapping("/assetFixedInventory")
@SecretBody
public class SmsAssetInventoryController {

    @Resource
    private SmsAssetInventoryService smsAssetInventoryService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;


    @ApiOperation("获取自己的盘点计划")
    @GetMapping("/getMyPlanList")
    public ResponseResult getMyPlanList(@RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize,
                                        @RequestParam(value = "pageNum", defaultValue = "1")Integer pagNum,
                                        HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetInventoryService.getMyPlanList(userId,pagNum,pageSize);
    }

    @ApiOperation("获取已盘点/未盘点的资产列表")
    @GetMapping("/getInventoryAssetList")
    public ResponseResult getInventoryAssetList(@RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize,
                                                @RequestParam(value = "pageNum", defaultValue = "1")Integer pagNum,
                                                @RequestParam(value = "planId") String planId,
                                                @RequestParam(value = "assetId",required = false) String assetId,
                                                @RequestParam(value = "inventoryId",required = false) String inventoryDetailId,
                                                @RequestParam(value = "type") Integer type,//1:我已盘 2:未盘点
                                                @RequestParam(value = "searchStr",required = false)String searchStr,
                                                @RequestParam(value = "assetStatus",required = false) Integer assetStatus,
                                                @RequestParam(value = "isComplete",required = false) Integer isComplete,
                                                HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetInventoryService.getInventoryAssetList(pagNum, pageSize,userId,planId,searchStr,assetStatus,isComplete,assetId,type,inventoryDetailId);
    }

    @ApiOperation("完成单个物品盘点")
    @PostMapping("/finishOneAsset")
    public ResponseResult finishOneAsset(HttpServletRequest request,@RequestBody SmsAssetInventoryDetailReq req) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetInventoryService.finishOneAsset(userId,req);
    }



    @ApiOperation("完成全部盘点")
    @PostMapping("/finishAll")
    public ResponseResult finishAll(HttpServletRequest request,@RequestBody SmsAssetInventoryPlanFinishReq finishReq) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetInventoryService.finishAll(userId,finishReq);
    }


    @ApiOperation("获取所有盘点的资产列表")
    @GetMapping("/getInventoryAssetAllList")
    public ResponseResult getInventoryAssetAllList(@RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize,
                                                @RequestParam(value = "pageNum", defaultValue = "1")Integer pagNum,
                                                @RequestParam(value = "planId") String planId,
                                                @RequestParam(value = "inventoryUserName") String inventoryUserName,
                                                @RequestParam(value = "searchStr",required = false)String searchStr,
                                                @RequestParam(value = "assetStatus",required = false) Integer assetStatus,
                                                @RequestParam(value = "isComplete",required = false) Integer isComplete) {
        return smsAssetInventoryService.getInventoryAssetAllList(pagNum, pageSize,planId,searchStr,assetStatus,isComplete,inventoryUserName);
    }

}

